import paddle.nn as nn
import numpy as np
class gCNN(nn.Layer):
    def __init__(self,
                in_channels=3,
                out_channels=101,
                cls_dim=[101,56,4],
                kernel_size=[1,3,5,7]):
        super(gCNN, self).__init__()
        self.in_c = in_channels
        self.out_c = out_channels 
        self.kernel_s = kernel_size
        self.cls_dim = cls_dim
        for k in self.kernel_s:
            self.conv_branch = nn.Sequential()
            self.conv_branch.add_sublayer('conv', nn.Conv2D(in_channels=self.in_c, 
                                                        out_channels=self.out_c,
                                                        kernel_size=k, padding=k // 2, 
                                                        bias_attr=False))
            self.conv_branch.add_sublayer('bn', nn.BatchNorm2D(self.out_c))
            self.conv_branch.add_sublayer('act', nn.ReLU())
            self.conv_branch.add_sublayer('pool', nn.AdaptiveAvgPool2D(output_size=[*self.cls_dim[1:]]))
            self.__setattr__('gconv{}'.format(k), self.conv_branch) 
    def forward(self,x):
        x1 = self.gconv1(x)
        x2 = self.gconv3(x)
        x3 = self.gconv5(x)
        x4 = self.gconv7(x)
        return x1+x2+x3+x4